package com.archie.zhufengfm.fragments.home.discover;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.archie.zhufengfm.Constants;
import com.archie.zhufengfm.R;
import com.archie.zhufengfm.fragments.home.BaseFragment;
import com.archie.zhufengfm.tasks.DiscoverCategoryTask;
import com.archie.zhufengfm.tasks.TaskCallback;
import com.archie.zhufengfm.tasks.TaskResult;

import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class DiscoverCategoryFragment extends BaseFragment implements TaskCallback {


    public DiscoverCategoryFragment() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        DiscoverCategoryTask task = new DiscoverCategoryTask(this);

        task.execute();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_discover_category, container, false);
    }


    @Override
    public String getFragmentTitle() {
        return "分类";
    }

    @Override
    public void onTaskFinished(TaskResult result) {

        if (result != null) {

            int action = result.action;

            if(action == Constants.TASK_ACTION_DISCOVER_CATEGORIES){

                // TODO 结果是从 发现-分类 任务中返回的，获取的就是分类
                if(result.resultCode == Constants.TASK_RESULT_OK){

                    // TODO 加载成功
                    Object data = result.data;
                    if (data != null && data instanceof List) {

                        List list = (List) data;

                        Log.d("Category", "List = " + list);
                    }

                }else{

                    // TODO 加载失败
                    Log.d("Category", "失败");
                }

            }

        }

    }
}
